package com.dilean.impl.model.attrval;

import com.dilean.api.model.Attribute;

public abstract class AttrValueAbstract<V>
{
    private Attribute attribute;
    private V value;
    private int personId;
    
    public Attribute getAttribute()
    {
        return attribute;
    }
    
    public void setAttribute(Attribute attribute)
    {
        this.attribute = attribute;
    }
    
    public Integer getPersonId()
    {
        return personId;
    }
    
    public void setPersonId(int personId)
    {
        this.personId = personId;
    }

    public V getValue()
    {
        return value;
    }
    
    public void setValue(V value)
    {
        this.value = value;
    }
    
    @Override
    public int hashCode()
    {
        return attribute.getId() * 31 + personId;
    }
    
    @Override
    public boolean equals(Object o)
    {
        if (o == null || !(o instanceof AttrValueAbstract))
            return false;
        
        AttrValueAbstract<?> avl = (AttrValueAbstract<?>) o;
        
        return avl.attribute.getId().equals(attribute.getId()) && avl.personId == personId;
    }
    
    @Override
    public String toString()
    {
    	return "AV[attr=" + (attribute  == null ? null : attribute.getName())+ "#val=" + value + "]";
    }
}
